package com.bit.blog.controller;

import com.bit.blog.pojo.request.AddBlogRequest;
import com.bit.blog.pojo.request.UpdateBlogRequest;
import com.bit.blog.pojo.response.BlogInfoResponse;
import com.bit.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {
    //进行博客列表的接口的设定；
    @Resource(name = "blogServiceImpl")//进行指定要注入的是什么；
    private BlogService blogService;
    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList(){
        log.info("获取博客链表");
        List<BlogInfoResponse> blogInfos= blogService.getList();
        return blogInfos;

    }
    //获取博客详情接口的设置；
    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull  Integer blogId){
        //@NotNull指定相关属性不能为空；
        log.info("获取博客详情，blog:{}",blogId);
        return blogService.getBlogDetail(blogId);
    }
    //进行添加博客；
    @RequestMapping("/add")
    public Boolean addBlog(@RequestBody @Validated AddBlogRequest addBlogRequest){
        log.info("发布博客，userId:{} ,title :{} ",addBlogRequest.getUserId(),addBlogRequest.getTitle());
        return blogService.addBlog(addBlogRequest);
    }
    //进行博客的编辑；
    @RequestMapping("/update")
    public Boolean update(@RequestBody @Validated UpdateBlogRequest updateRequest){
        log.info("更新博客， request:{}",updateRequest);
        return blogService.updateBlog(updateRequest);
    }

@RequestMapping("/delete")
    public Boolean delete(@NotNull(message = "id不能为空") Integer blogId){
        log.info("删除博客，id：{}",blogId);
        return blogService.deleteBlog(blogId);
}
}
